<template>
  <!-- xuxinjie -->
  <Layout :class="'bg-white p-2'">
    <Row :class="'m-1'"> </Row>
    <Row align="middle">
      <Col span="13">
        <Input
          :class="'w-100 m-4'"
          v-model="name"
          placeholder="请输入查重人的姓名"
        />
      </Col>
      <Col span="1"> </Col>
      <Col span="10">
        <Button
          class="'w-100 m-2'"
          type="primary"
          shape="circle"
          @click="search"
          icon="ios-search"
          >线索查重</Button
        >
      </Col>
    </Row>

    <Layout :class="'bg-white'">
      <Table
        border
        :class="'m-1'"
        :columns="tableInfo.columnInfo"
        :data="tableInfo.data"
      >
        <template slot-scope="{ row, index }" slot="status">
          <span v-if="row.statu">开</span>
          <span v-else>关</span>
        </template>
        <template slot-scope="{ row, index }" slot="action">
          <Button
            type="primary"
            size="small"
            style="margin-right: 10px"
            @click="show(row.roleId)"
            >详细</Button
          >
          <Button type="error" size="small" @click="remove(row.roleId)"
            >删除</Button
          >
          <Dropdown>
            <Button type="info" size="small" style="margin-left: 5px">
              其他
              <Icon type="ios-arrow-down"></Icon>
            </Button>
            <DropdownMenu slot="list" transfer="true" stop-propagation="true">
              <DropdownItem>修改</DropdownItem>
              <DropdownItem>分配</DropdownItem>
            </DropdownMenu>
          </Dropdown>
        </template>
      </Table>
    </Layout>
  </Layout>
</template>

<script>
export default {
  data() {
    return {
      autorName: '',
      name: '',

      tableInfo: {
        currentPage: 1,
        total: 0,
        pageSize: 1,
        columnInfo: [
          {
            title: '姓名',
            key: 'name',
          },
          {
            title: '联系电话',
            key: 'tel',
          },
          {
            title: '线索状态',
            key: 'statu',
          },
          {
            title: '跟进人',
            key: 'autor',
          },
        ],
        data: [],
      },
    }
  },
  methods: {
    init: function() {
      this.$data.tableInfo.currentPage = 0
    },
    newRole: function() {
      this.$router.push({
        name: 'resource_duplication_new',
      })
    },
    show: function(roleId) {
      this.$router.push({
        name: 'role_detail',
        params: {
          roleId,
        },
      })
    },

    search: function() {
      this.http
        .get({
          url: `resource/duplication/${this.$data.name}`,
        })
        .then((data) => {
          let userList = JSON.parse(localStorage.getItem('USER_LIST'))

          this.$data.tableInfo.currentPage = 1
          this.$data.tableInfo.total = 1
          this.$data.tableInfo.pageSize = 1
          //表格数据配置
          let POJOList = new Array()
          let POJO = {
            studentId: null,
            resourceId: null,
            tel: null,
            name: null,
            statu: null,
            autor: null,
          }
          for (let item in data) {
            userList.forEach((user) => {
              if (user.userId == data[item].resource.autor) {
                this.autorName = user.nickName
              }
            })
            POJO = {
              studentId: data[item].student.id,
              resourceId: data[item].resource.id,
              tel: data[item].student.tel,
              name: data[item].student.name,
              statu: data[item].resource.statu,
              autor: this.autorName,
            }
            POJOList.push(POJO)
          }
          this.$data.tableInfo.data = POJOList
        })
    },

    pageSearch: function(changedPage) {
      this.$data.tableInfo.currentPage = changedPage
      this.search()
    },
    remove: function(roleId) {
      this.message.confirm({
        title: '删除提示',
        content: '即将删除角色，确定吗？',
        onOk: () => {
          this.http
            .delete({
              url: '/role/info',
              param: {
                roleId,
              },
            })
            .then((data) => {
              this.search()
            })
        },
        onCancel: () => {
          this.message.info('操作已取消')
        },
      })
    },
  },
  created: function() {
    this.init()
  },
}
</script>

<style></style>
